﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace theguineasyndrome
{
    public class LevelCell
    {
        public const int SIZE = 256;

        private List<LevelElement> elements;
        private List<ObstacleElement> obstacleElements;
        private List<Enemy> enemies;
        private List<Carot> carots;

        private Rectangle rectangle;

        private Color color;

        private static Random random = new Random();

        public LevelCell(Vector2 position)
        {
            rectangle = new Rectangle((int) position.X, (int)position.Y, SIZE, SIZE);
            elements = new List<LevelElement>();
            carots = new List<Carot>();
            obstacleElements = new List<ObstacleElement>();
            enemies = new List<Enemy>();
            color = new Color((float)random.NextDouble() / 2 + 0.5f, (float)random.NextDouble() / 2 + 0.5f, (float)random.NextDouble() / 2 + 0.5f);
        }

        public void addElement(LevelElement element)
        {
            //element.setColor(color);

            if (element is ObstacleElement)
                obstacleElements.Add((ObstacleElement)element);

            else if (element is Carot)
                carots.Add((Carot)element);

            else if (element is Enemy)
                enemies.Add((Enemy)element);

            elements.Add(element);
        }

        public void removeElement(LevelElement element)
        {
            if (element is ObstacleElement)
                obstacleElements.Remove((ObstacleElement)element);

            else if (element is Carot)
                carots.Remove((Carot)element);

            else if (element is Enemy)
                enemies.Remove((Enemy)element);

            elements.Remove(element);
        }

        public List<ObstacleElement> getObstacleElements()
        {
            return obstacleElements;
        }

        public List<LevelElement> getElements()
        {
            return elements;
        }

        public List<Carot> getCarots()
        {
            return carots;
        }

        public List<Enemy> getEnemies()
        {
            return enemies;
        }

        public void queueDrawing(Camera camera)
        {
            foreach (LevelElement element in elements)
                element.queueDrawing(camera);
        }

        public float Left
        {
            get { return rectangle.Left; }
        }

        public float Right
        {
            get { return rectangle.Right; }
        }

        public float Top
        {
            get { return rectangle.Top; }
        }

        public float Bottom
        {
            get { return rectangle.Bottom; }
        }
    }
}
